package PTA.Mianxiangduixiang.ex04;

import java.util.Arrays;
import java.util.Scanner ;
abstract class  Shape{
    static double PI=3.14;
    public abstract double getPerimeter();
    public abstract double getArea();
}
class Rectangle extends Shape{
private int width;
private int length;
Rectangle(int width,int length){
    this.width=width;
    this.length=length;
}
Rectangle(){}
    @Override
    public double getPerimeter() {
        return (width+length)*2;
    }

    @Override
    public double getArea() {
        return width*length;
    }

    @Override
    public String toString() {
        return "Rectangle [" +
                "width=" + width +
                ", length=" + length +
                ']';
    }
}

class Circle extends Shape{
private int radius;
    Circle(){}
    Circle(int radius){
        this.radius=radius;
    }
    @Override
    public double getPerimeter() {
        return 2*PI*radius;
    }

    @Override
    public double getArea() {
        return PI*radius*radius;
    }

    @Override
    public String toString() {
        return "Circle [" +
                "radius=" + radius +
                ']';
    }
}

public class ex04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Shape []arr = new Shape[n];
        sc.nextLine();
        for(int i=0;i<n;i++){
            String line = sc.nextLine();

            if(line.equals("rect")){
                int width = sc.nextInt();
                int length = sc.nextInt();
                arr[i]=new Rectangle(width,length);
                sc.nextLine();
            }else if(line.equals("cir")){
                int radius = sc.nextInt();
                arr[i]=new Circle(radius);
                sc.nextLine();
            }
        }
        System.out.println(sumAllPerimeter(arr));
        System.out.println(sumAllArea(arr));
        System.out.println(Arrays.toString(arr));
        for(Shape s:arr){
            System.out.println(s.getClass()+","+s.getClass().getSuperclass());
        }
    }
    public static double sumAllPerimeter(Shape []s){
        double sum=0;
        for(Shape ss:s){
            sum+=ss.getPerimeter();

        }
return sum;
    }
    public static double sumAllArea(Shape []s){
        double sum=0;
        for(Shape ss:s){
            sum+=ss.getArea();
        }
        return sum;
    }
}
